package com.cykj.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * Project:boot-maven
 * Package:com.cykj.dto
 *
 * @Description:统一格式发送给前端
 * @Author:其一
 * @CreateTime: 2025-05-16-14-51
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResponseDTO {
    private Integer code;//状态码
    private String msg;//提示
    private Object data;//数据

    private static final Integer SUCCESS_CODE = 200;
    private static final Integer ERROR_CODE = 500;


    public static ResponseDTO success(Object data) {
        return new ResponseDTO(SUCCESS_CODE, "操作成功", data);
    }

    public static ResponseDTO success(String msg) {
        return new ResponseDTO(SUCCESS_CODE, msg, null);
    }

    public static ResponseDTO success(String msg, Object data) {
        return new ResponseDTO(SUCCESS_CODE, msg, data);
    }

    public static ResponseDTO error(Integer code,String msg, Object data) {
        return new ResponseDTO(code, msg, data);
    }

    public static ResponseDTO error(Integer code,String msg) {
        return new ResponseDTO(code,msg,null);
    }

    public static ResponseDTO error() {
        return new ResponseDTO(ERROR_CODE, "操作失败", null);
    }

    public static ResponseDTO error(String msg) {
        return new ResponseDTO(ERROR_CODE, msg, null);
    }

}
